package com.example.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 读取properity文件
 * @ClassName: ReadProperties.java
 * @Description:
 * @author: xiaozhijun
 * @Date: 2016年9月22日 下午2:16:33
 */
public class ReadProperties {
	private static final Logger LOG = LoggerFactory.getLogger(ReadProperties.class);
	
	public Properties prop;
	
	public ReadProperties(String path){
		prop = new Properties();// 属性集合对象 
		InputStream in = ReadProperties.class.getClassLoader().getResourceAsStream(path);
        try {
			prop.load(in);
		} catch (IOException e) {
			LOG.info("读取配置文件" + path +"失败:" + e.getMessage());
		}finally{
			try {
				if(in != null){
					in.close();
				}	
			} catch (IOException e) {
				LOG.info("关闭读取流失败:" + e.getMessage());
			}
		}// 将属性文件流装载到Properties对象中    
        
	}
	
	/**
	 * 
	 * 
	 * @author xiaozhijun
	 * @Date: 2016年9月22日 下午2:15:54
	 * @param key
	 * @return
	 */
	public String getProByField(String key){
		return prop.getProperty(key).trim();
	}
}
